package priv.pfz.raft.peer.model;

import com.google.common.primitives.Ints;
import lombok.AllArgsConstructor;
import lombok.Getter;
import priv.pfz.raft.common.ToString;

/**
 * @author pengfangzhou
 * @date 2022/2/8 0:47
 */
@Getter
@AllArgsConstructor
public class LogKey extends ToString implements Comparable<LogKey> {
    private final int term;
    private final int index;

    public static final LogKey DEFAULT = new LogKey(0, 0);

    @Override
    public int compareTo(LogKey o) {
        int termResult = Ints.compare(term, o.term);
        if (termResult != 0) {
            return termResult;
        }
        return Ints.compare(index, o.index);
    }
}
